﻿using System;
using System.Text;
using System.Data;
using System.Collections.Generic;

using MySql.Data.MySqlClient;
using Think.Lenovo.Com.Models;
using Think.Lenovo.Com.Common;
using Think.Lenovo.Com.Models.Questionnaire;

namespace Think.Lenovo.Com.DataAccess.Questionnaire
{
    public class QuestionOptionsRelation
    {
        public long Add(QuestionOptionsRelationModel model)
        {
            String conn = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlHost"].ConnectionString;

            //sql语句
            StringBuilder sql = new StringBuilder(128);
            sql.Append("insert into ")
                .Append(" tbl_question_option_r (QuestionId, OptionId)")
                .Append(" values    (@QuestionId,@OptionId)");

            MySqlParameter[] ps = new MySqlParameter[]{ 
                    new MySqlParameter("@QuestionId",MySqlDbType.VarChar,56),
                    new MySqlParameter("@OptionId",MySqlDbType.VarChar,256)
                };

            ps[0].Value = model.QuestionId;
            ps[1].Value = model.OptionsId;

            long id = MysqlHelper.Insert(conn, sql.ToString(), ps);
            return id;
        }
        public int Delete(int questionId)
        {
            String conn = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlHost"].ConnectionString;

            //sql语句
            StringBuilder sql = new StringBuilder(128);
            sql.Append("Delete From ")
                .Append(" tbl_question_option_r ")
                .Append("  Where questionId="+questionId);

            int affected = MysqlHelper.Delete(conn, sql.ToString(), null);
            return affected;
        }
    }
}
